package homework;

import java.util.ArrayList;
import java.util.List;

public class SubListDemo {
    public static void main(String[] args) {

        List<Integer> list=new ArrayList<>();
        list.add(10);
        list.add(20);
        list.add(30);
        list.add(40);
        list.add(50);
        System.out.println("list:"+list);
        List<Integer> subList=list.subList(1,4);
        System.out.println("subList:"+subList);
        for(int i=0;i<subList.size();i++){
            subList.set(i,subList.get(i)*10);//对子集中的元素操作就是对原集合中的元素操作，反之同理
        }
        System.out.println("subList:"+subList);
        System.out.println("list:"+list);
        list.add(1,100);//原集合如果改变长度，子集不能进行任何操作，否则发生异常
        System.out.println("subList:"+subList);//ConcurrentModificationException
        System.out.println("list:"+list);
    }
}
